package 简单.检查平衡性;

import java.util.Map;

public class Solution1 {
    public boolean isBalanced(TreeNode root) {
        if(root == null) return true;
        int left = helper(root.left);
        int right = helper(root.right);
        if(Math.abs(left-right)>1){
            return false;
        }
        return isBalanced(root.left) && isBalanced(root.right);
    }

    public int helper(TreeNode node) {

        if (node == null) return 0;
        return Math.max(helper(node.left), helper(node.right)) + 1;
    }
}
